import numpy as np

# 线性运动
def linear(frames, min=0, max=1):
  if max < min:
    raise ValueError('max不能小于min')
  step = (max - min) / (frames - 1)
  stepsList = []
  for i in range(0, frames):
    result = step * i
    stepsList.append(int(result))
  return stepsList 

def linearFloat(frames, min=0, max=1):
  if max < min:
    raise ValueError('max不能小于min')
  step = (max - min) / (frames - 1)
  stepsList = []
  for i in range(0, frames):
    result = round(step * i, 3)
    stepsList.append(result)
  return stepsList 

# q:quick s:slow 快慢快线性运动
def qsqLinear(frames, min=0, max=1, areaRate=[0.4, 0.02, 0.58], frameRate=[0.4, 0.35, 0.25]):
  ### 通过控制areaRate和frameRate对应位置的比率调整速度
  ### areaRate为0.4代表总大小的40%，frameRate为0.45代表总帧数的45%
  ### 使用总帧数的45%，移动40%的距离
  if max < min:
    raise ValueError('max不能小于min')
  if sum(areaRate) != 1:
    raise ValueError('areaRate加和必须等于1')
  scope = max - min
  step = []
  result = []

  for i in range(0, 3):
    rate = int(scope*areaRate[i]) / int(frames*frameRate[i])
    step.append(rate)
  
  temRes = 0
  for i, item in enumerate(step):
    for j in range(0, int(frames*frameRate[i])):
      result.append(int(temRes))
      temRes += item
  result.append(scope)
  return result

# 先慢后快线性运动
def sqLinear(frames, min=0, max=0, frameRate=[0.7, 0.3]):
  if max < min:
    raise ValueError('max不能小于min')
  scope = max - min
  result = []

  steps= []
  for i in range(0, 2):
    step = scope / int(frames*frameRate[i])
    steps.append(step)

  for i, item in enumerate(steps):
    for j in range(0, int(frames*frameRate[i])):
      if i == 0:
        result.append(min + j*steps[i])
      else:
        result.append(max - j*steps[i])  
  result.append(1)
  return result